package com.example.system.class20;

/**
 * @Date 2022/8/13
 * @Author Jonathan
 */
public class Code02_ConvertToLetterString {
    public static void main(String[] args) {
        System.out.println(convert("305"));
        System.out.println(convert("111"));
    }

    public static int convert(String str) {
        final char[] chars = str.toCharArray();
        return process(chars, 0);
    }


    public static int process(char[] chars, int index) {
        //  转化完了
        if (index == chars.length) {
            return 1;
        }

        if (chars[index] == '0') {
            return 0;
        }
        int p1 = process(chars, index + 1);
        if (index + 1 < chars.length && ((chars[index] - '0') * 10 + chars[index + 1] - '0') < 27) {
            p1 += process(chars, index + 2);
        }
        return p1;
    }
}
